let base = Module.getBaseAddress('MTPotal')
console.log('base', base)
// console.log(Instruction.parse(base.add(0x5b1c)))
// console.log(Instruction.parse(base.add(0x5b20)))

// Interceptor.attach(Module.getExportByName('libsystem_kernel.dylib', 'csops'), {
//     onEnter: function(args) {
//         console.log('[*] csops called');
//         console.log('PID: ' + args[0].toInt32());
//         console.log('Operation: ' + args[1].toInt32());
//         console.log('User address: ' + args[2]);
//         console.log('User size: ' + args[3].toInt32());
//         this.useraddr = args[2];  // 保存缓冲区地址
//         this.usersize = args[3].toInt32();  // 保存缓冲区大小
//         this.ops = args[1].toInt32();  // 保存操作类型
//     },
//     onLeave: function(retval) {
//         console.log('[*] csops returned: ' + retval.toInt32());
//         if (retval.toInt32() === 0 && this.useraddr != 0 && this.usersize > 0) {
//             // 如果成功且缓冲区非空，读取数据
//             if (this.ops === 6) {  // CS_OPS_ENTITLEMENTS_BLOB
//                 console.log('Entitlements: ' + Memory.readUtf8String(this.useraddr, this.usersize));
//             } else if (this.ops === 4) {  // CS_OPS_CDHASH
//                 console.log('CDHash: ' + hexdump(this.useraddr, { length: this.usersize }));
//             } else {
//                 console.log('Data: ' + hexdump(this.useraddr, { length: this.usersize }));
//             }
//         }
//     }
// });


var NSString = ObjC.classes.NSString;

// function getNSString(str) {
//     return NSString.stringWithUTF8String_(Memory.allocUtf8String(str));
// }
Interceptor.attach(Module.getExportByName('libsystem_kernel.dylib', 'getentropy'), {
    onEnter: function(args) {
        console.log('[*] getentropy called');
        console.log('Buffer pointer: ' + args[0]);
        console.log('Length: ' + args[1].toInt32());
        this.buffer = args[0];  // 保存 buffer 地址用于 onLeave
        this.length = args[1].toInt32();  // 保存 length
    },
    onLeave: function(retval) {
        console.log('[*] getentropy returned: ' + retval.toInt32());
        if (this.length === 32){
            this.buffer.writeByteArray([109, 65, 85, 98, 115, 212, 252, 205, 26, 142, 45, 232, 196, 15, 254, 147, 132, 222, 117, 71, 217, 210, 106,
                193, 252, 188, 207, 184, 74, 63, 238, 221])
        }
        if (this.length === 64){
            this.buffer.writeByteArray([54, 208, 131, 174, 42, 17, 167, 137, 57, 220, 78, 219, 150, 75, 216, 141, 39, 17, 189, 108, 144, 40, 51, 6,
                226, 99, 238, 210, 48, 197, 226, 182, 100, 197, 22, 12, 192, 22, 159, 212, 236, 234, 139, 107, 70, 25, 106,
                217, 249, 201, 158, 36, 17, 148, 110, 251, 106, 138, 203, 254, 169, 154, 187, 2])
        }
        if (retval.toInt32() === 0) {  // 如果成功
            console.log('Random data: ' + hexdump(this.buffer, { length: this.length }));
        }
    }
});

Interceptor.attach(Module.getExportByName(null, 'gettimeofday'), {
    onEnter: function(args) {
        // console.log('[*] gettimeofday called');
        // console.log('timeval pointer: ' + args[0]);
        // console.log('timezone pointer: ' + args[1]);
        this.timevalPtr = args[0];  // 保存 timeval 指针
        this.timezonePtr = args[1]; // 保存 timezone 指针
    },
    onLeave: function(retval) {
        // console.log('[*] gettimeofday returned: ' + retval.toInt32());
        this.timevalPtr.writeLong(1741759941)
        this.timevalPtr.add(8).writeLong(0)
        if (retval.toInt32() === 0 && this.timevalPtr != 0) {  // 如果成功且时间指针非空
            var tv_sec = Memory.readLong(this.timevalPtr);
            // 读取秒
            var tv_usec = Memory.readLong(this.timevalPtr.add(8)); // 读取微秒 (假设 64 位系统)
            // console.log('Time: ' + tv_sec + ' seconds, ' + tv_usec + ' microseconds');
        }
        if (this.timezonePtr != 0) {  // 如果时区指针非空
            var tz_minuteswest = Memory.readInt(this.timezonePtr);
            var tz_dsttime = Memory.readInt(this.timezonePtr.add(4));
            // console.log('Timezone: ' + tz_minuteswest + ' minutes west, DST: ' + tz_dsttime);
        }
    }
});
//
//
// Interceptor.attach(Module.getExportByName('libSystem.B.dylib', 'mach_absolute_time'), {
//     onEnter: function(args) {
//         // console.log('[*] mach_absolute_time called');
//     },
//     onLeave: function(retval) {
//         // console.log('[*] mach_absolute_time returned: ' + retval.toString());
//         // 将时间转换为可读格式（需要时间基准）
//         retval.replace(1090123063000)
//         // var timebase = Memory.alloc(8); // 分配 mach_timebase_info 结构体空间
//         // var mach_timebase_info = new NativeFunction(
//         //     Module.getExportByName('libSystem.B.dylib', 'mach_timebase_info'),
//         //     'int', ['pointer']
//         // );
//         // mach_timebase_info(timebase);
//         // var numer = Memory.readU32(timebase);
//         // var denom = Memory.readU32(timebase.add(4));
//         // var nanoseconds = (retval.toInt64() * numer) / denom;
//         // console.log('Time in nanoseconds: ' + nanoseconds);
//     }
// });
// Interceptor.attach(Module.getExportByName('libSystem.B.dylib', 'mach_timebase_info'), {
//     onEnter: function(args) {
//         console.log('[*] mach_timebase_info called');
//         console.log('Info pointer: ' + args[0]);
//         this.infoPtr = args[0];  // 保存结构体指针
//     },
//     onLeave: function(retval) {
//         console.log('[*] mach_timebase_info returned: ' + retval.toInt32());
//         if (retval.toInt32() === 0 && this.infoPtr != 0) {  // 如果成功且指针非空
//             var numer = Memory.readU32(this.infoPtr);      // 读取分子
//             var denom = Memory.readU32(this.infoPtr.add(4)); // 读取分母
//             console.log('Timebase: numer = ' + numer + ', denom = ' + denom);
//             console.log('1 Mach unit = ' + (numer / denom) + ' nanoseconds');
//         }
//     }
// });

// Interceptor.attach(Module.getExportByName('libSystem.B.dylib', 'mach_msg'), {
//     onEnter: function(args) {
//         console.log('[*] mach_msg called');
//         console.log('Message pointer: ' + args[0]);
//         console.log('Option: ' + args[1].toInt32());
//         console.log('Send size: ' + args[2].toInt32());
//         console.log('Receive size: ' + args[3].toInt32());
//         console.log('Receive port: ' + args[4].toInt32());
//         console.log('Timeout: ' + args[5].toInt32());
//         console.log('Notify port: ' + args[6].toInt32());
//
//         this.msgPtr = args[0];  // 保存消息指针
//         this.option = args[1].toInt32();  // 保存选项
//
//         // 如果是发送或接收消息，读取消息头
//         if (this.msgPtr != 0) {
//             var msgh_bits = Memory.readU32(this.msgPtr);
//             var msgh_size = Memory.readU32(this.msgPtr.add(4));
//             var msgh_remote_port = Memory.readU32(this.msgPtr.add(8));
//             var msgh_local_port = Memory.readU32(this.msgPtr.add(12));
//             var msgh_id = Memory.readU32(this.msgPtr.add(20));
//             console.log('Message header:');
//             console.log('  msgh_bits: ' + msgh_bits);
//             console.log('  msgh_size: ' + msgh_size);
//             console.log('  msgh_remote_port: ' + msgh_remote_port);
//             console.log('  msgh_local_port: ' + msgh_local_port);
//             console.log('  msgh_id: ' + msgh_id);
//         }
//     },
//     onLeave: function(retval) {
//         console.log('[*] mach_msg returned: ' + retval.toInt32());
//         if (retval.toInt32() === 0 && this.msgPtr != 0 && (this.option & 0x2)) {  // MACH_RCV_MSG
//             // 如果是接收消息，读取返回的数据
//             console.log('Received message: ' + hexdump(this.msgPtr, { length: Memory.readU32(this.msgPtr.add(4)) }));
//         }
//     }
// });


// Interceptor.attach(Module.getExportByName('libSystem.B.dylib', 'sigprocmask'), {
//     onEnter: function(args) {
//         console.log('[*] sigprocmask called');
//         console.log('How: ' + args[0].toInt32());
//         console.log('Set pointer: ' + args[1]);
//         console.log('Oldset pointer: ' + args[2]);
//
//         this.how = args[0].toInt32();
//         this.setPtr = args[1];
//         this.oldsetPtr = args[2];
//
//         // 读取新信号集
//         if (this.setPtr != 0) {
//             var sigset = Memory.readU32(this.setPtr);
//             console.log('New signal set: ' + sigset.toString(2)); // 以二进制显示
//         }
//     },
//     onLeave: function(retval) {
//         console.log('[*] sigprocmask returned: ' + retval.toInt32());
//         if (retval.toInt32() === 0 && this.oldsetPtr != 0) {
//             // 如果成功且 oldset 非空，读取旧信号集
//             var old_sigset = Memory.readU32(this.oldsetPtr);
//             console.log('Old signal set: ' + old_sigset.toString(2));
//         }
//     }
// });


// let appKey = getNSString('9101430221728_IOS')
// let api = getNSString('alipay.client.updateVersion')
// let signData = getNSString('Operation-Type=alipay.client.updateVersion&Request-Data=AwAAIQKam1t89igK9npOsZxIjK6jrKbbIuUJZXroLaNjg1hJVA0AAPBY0pwCzzaUGTpmF+udid85IDj8sA8k+E5fFyAVz/NyGas8d8Cog4f97Zobnr5OoEd7yUNVkn8o+UGGmr5HsGKph1gH4oBZwVaPhcE/VDU0Cg/W5s3Bc7FpSDu9BvjOfWuwOAgPEoSNndCuBWQntIcHDvR7kGfh0nQ8xxwzkIOPkzgt4NOE0T+Z+u6BDJ6r0bOzRlUIULWfREZQcvkV0MI6fpOKQej3oh85VypYhuD+67+XVWrYz2Nn9SIaWWF1ifkUZe+ueouH17OlCcjlR+epEVw/kxaAYtzwUDG3nK7A/ucw0eEJR7sY8jwc7aOwubE=&Ts=PM3iDI7')
//
// let a = ObjC.classes['MPSignatureService']['sharedInstance']();
// let r = a['trustedSignBySignKey:signApi:content:'](appKey, api, signData)
//
//
// console.log(r['- objectForKey:'](getNSString('x-djy-color'))['- cStringUsingEncoding:'](4))
// console.log(r['- objectForKey:'](getNSString('x-djy-sign'))['- cStringUsingEncoding:'](4))





// Interceptor.attach(Module.getExportByName('libSystem.B.dylib', 'getegid'), {
//     onEnter: function(args) {
//         console.log('[*] getegid called');
//     },
//     onLeave: function(retval) {
//         console.log('[*] getegid returned effective group ID: ' + retval.toInt32());
//     }
// });

// Interceptor.attach(ObjC.classes['MTDeviceFPManage']['+ deviceFPData'].implementation, {
//     onEnter(args){
//         // console.log('loadTA', args[2])
//         // console.log(`-[MPSignatureService signByBlueShieldWithType:${args[2]} signKey:${new ObjC.Object(args[3])} autoCode:${args[4]} content:${args[5]}]`);
//         // console.log('auth', new ObjC.Object(args[4]))
//         // console.log('content', new ObjC.Object(args[5]))
//         // console.log('signType', obj['- objectForKey:']('signType'))
//     },
//     onLeave(ret){
//         console.log('retretretret', new ObjC.Object(ret))
//         //         console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         // .map(DebugSymbol.fromAddress).join('\n') + '\n')
//     }
// })

// Interceptor.attach(ObjC.classes['MTDeviceFPManage']['+ deviceFPData'].implementation, {
// Interceptor.attach(ObjC.classes['SM4Tool']['+ SM4WithCBCPKCS5Encrypt:keyString:ivSting:'].implementation, {
// // Interceptor.attach(ObjC.classes['DTRpcOperation']['- initWithURL:method:params:headerFields:amrpc:cdn:'].implementation, {
//     onEnter(args){
//         let body = new ObjC.Object(args[2]);
//         console.log('jsonObjectWithString:', body)
//         console.log('jsonObjectWithString:', new ObjC.Object(args[3]))
//         console.log('jsonObjectWithString:', new ObjC.Object(args[4]))
//         //         console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         // .map(DebugSymbol.fromAddress).join('\n') + '\n')
//     },
//     onLeave(ret){
//         let body = new ObjC.Object(ret);
//         console.log('v:', body)
//         //                 console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         // .map(DebugSymbol.fromAddress).join('\n') + '\n')
//     }
// })


// Interceptor.attach(ObjC.classes['AVCaptureDeviceDiscoverySession']['+ discoverySessionWithDeviceTypes:mediaType:position:'].implementation, {
//     onEnter(args){
//         console.log('loadTA', new ObjC.Object(args[2]), args[3])
//         // console.log(`-[MPSignatureService signByBlueShieldWithType:${args[2]} signKey:${new ObjC.Object(args[3])} autoCode:${args[4]} content:${args[5]}]`);
//         // console.log('auth', new ObjC.Object(args[4]))
//         // console.log('content', new ObjC.Object(args[5]))
//         // console.log('signType', obj['- objectForKey:']('signType'))
//     },
//     onLeave(ret){
//         console.log('screenHeight_scale', new ObjC.Object(ret))
//         //         console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         // .map(DebugSymbol.fromAddress).join('\n') + '\n')
//     }
// })
// console.log(1,Instruction.parse(base.add(0x45bF8 ) ))
// console.log(1,Instruction.parse(base.add(0x45bF8 ).add(4) ))
// Interceptor.attach(base.add(0x45bF8 ), {
//     onEnter(arg){
//
//         console.log(2,Instruction.parse(base.add(0x45bF8 ) ))
//         console.log(2,Instruction.parse(base.add(0x45bF8 ).add(4) ))
//         console.log('395578',JSON.stringify(this.context))
//         // console.log(1, new ObjC.Object(this.context.x1))
//         // console.log(1, new ObjC.Object(this.context.x2))
//         // console.log(1, new ObjC.Object(this.context.x3))
//         // console.log(2,new ObjC.Object(this.context.x4))
//
//         var tid = Process.getCurrentThreadId();
//         this.tid = tid;
//         Stalker.follow(tid, {
//             events: {
//                 call: true, // CALL instructions: yes please
//                 ret: false, // RET instructions
//                 exec: false, // all instructions: not recommended as it's
//                 block: false, // block executed: coarse execution trace
//                 compile: false // block compiled: useful for coverage
//             },
//             transform: (iterator) => {
//                 let instruction = iterator.next();
//                 const startAddress = instruction.address;
//                 var isAppCode = startAddress.compare(base.add(0x45bF8)) >= 0 && startAddress.compare(base.add(0x45bF8).add(10000)) === -1;
//                 do {
//                     if (isAppCode) {
//                         iterator.putCallout((context) => {
//                             console.log(context.pc.sub(base).add(0x100000000), instruction,JSON.stringify(context))
//                         })
//                     }
//                     iterator.keep();
//                 } while ((instruction = iterator.next()) !== null);
//
//             }
//         })
//
//     },
//     onLeave(ert){
//         Stalker.unfollow(this.tid);
//         Stalker.garbageCollect()
//     }
// })
//   // console.log('aaaa',ptr(base + 0x45ECC).readPointer().add(3).readU64());
//
let module = Process.getModuleByName('MTPotal');


Interceptor.attach(ObjC.classes['SIManager']['+ initSI:'].implementation, {
    onEnter(arg){

    },
    onLeave(ret){
        console.log('initSI:', ret)
    }
})
Interceptor.attach(ObjC.classes['SIManager']['+ initSI:'].implementation, {
    onEnter(arg){

    },
    onLeave(ret){
        console.log('initSI:', ret)
    }
})
//
// Interceptor.attach(ObjC.classes['APScpFrameworkManager']['+ initScpFramework'].implementation, {
//     onEnter(arg){
//
//     },
//     onLeave(ret){
//         console.log('APScpFrameworkManager:', ret)
//     }
// })
//
// Interceptor.attach(ObjC.classes['NSFileManager']['- fileExistsAtPath:'].implementation, {
//     onEnter(args){
//         console.log('fileExistsAtPath', new ObjC.Object(args[2]))
//     },
//     onLeave(ret){
//         console.log('fileExistsAtPath:', ret)
//     }
// })
//
Interceptor.attach(base.add(0xDF1B34), {
    onEnter(args){
        console.log('E1DEF0', args[0], args[1], args[2],args[3])
    },
    onLeave(ret){
        console.log('E1DEF0', ret)
    }
})
// var strlen = Module.findExportByName(null, "strlen");
// console.log('strlen', strlen)
// Interceptor.attach(base.add(0xdF0A40), {
//     onEnter(args){
//         // console.log('strlen', args[0].readCString())
//         console.log('br', JSON.stringify(this.context))
//         console.log('F0A40', args[0], args[1], args[2])
//         console.log('a1', hexdump(args[1],{length:0x30}))
//         console.log('a2', hexdump(args[2],{length:0x30}))
//         console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         .map(DebugSymbol.fromAddress).join('\n') + '\n')
//         args[1].writeUtf8String('cn.12306.rails12306')
//         args[2].writeUtf8String('GRN4JMHD49')
//         console.log('a1', hexdump(args[1], {length:0x30}))
//         console.log('a2', hexdump(args[2], {length:0x30}))
//     }
// })

// Interceptor.attach(base.add(0xEF92EC), {
//     onEnter(args){
//         console.log('EF92EC', JSON.stringify(this.context))
//     }
// })
// Interceptor.attach(base.add(0xEEB9BC), {
//     onEnter(args){
//         console.log('EEB9BC', args[0], args[1])
//         console.log('EEB9BC', JSON.stringify(this.context))
//         // console.log('0x10a0b4200 x1', hexdump(this.context.x1))
//         // console.log('0x10a0b4200 x5', hexdump(this.context.x5))
//         this.a0 = args[0]
//         console.log('EEB9BC', hexdump(args[0], ))
//         // MemoryAccessMonitor.enable({base: args[0], size:0x40}, {
//         //     onAccess(details){
//         //         console.log(details)
//         //
//         //     }
//         // })
//         var tid = Process.getCurrentThreadId();
//         this.tid = tid;
//         // Stalker.follow(tid, {
//         //     events: {
//         //         call: true, // CALL instructions: yes please
//         //         ret: false, // RET instructions
//         //         exec: false, // all instructions: not recommended as it's
//         //         block: false, // block executed: coarse execution trace
//         //         compile: false // block compiled: useful for coverage
//         //     },
//         //     transform: (iterator) => {
//         //         let instruction = iterator.next();
//         //         const startAddress = instruction.address;
//         //         var isAppCode = startAddress.compare(base.add(0xEEB9BC)) >= 0 && startAddress.compare(base.add(0xEEB9BC).add(10000)) === -1;
//         //         do {
//         //             if (isAppCode) {
//         //                 console.log(instruction.address.sub(base), instruction, '|', instruction.regsRead, '|', instruction.regsWritten);
//         //             }
//         //             iterator.keep();
//         //         } while ((instruction = iterator.next()) !== null);
//         //
//         //     }
//         // })
//     },
//     onLeave(ret){
//         console.log('EEB9BC.ret', ret)
//         // this.a0.writeUtf8String('cn.12306.rails12306')
//         // this.a0.add(0x40).writeUtf8String('GRN4JMHD49')
//         // console.log('EEB9BC.ret', hexdump(this.a0))
//         Stalker.unfollow(this.tid);
//         Stalker.garbageCollect()
//     }
// })
// Memory.scan(base, module.size, '410271', {
//     onMatch(add,size){
//         console.log(add.sub(base).add(0x100000000))
//         // let a = add.sub(base).add(0x100000000)
//         //
//         // for (let i = 0; i < 4; i++) {
//         //     console.log(a, Instruction.parse(add.sub(1).add(4*i)))
//         //
//         // }
//     }
// })
const CFStringGetCStringPtr = new NativeFunction(
    Module.getExportByName('CoreFoundation', 'CFStringGetCStringPtr'),
    'pointer', ['pointer', 'uint32']
);

const CFGetTypeID = new NativeFunction(
    Module.getExportByName('CoreFoundation', 'CFGetTypeID'),
    'uint', ['pointer']
);
const CFStringGetTypeID = new NativeFunction(
    Module.getExportByName('CoreFoundation', 'CFStringGetTypeID'),
    'uint', []
);

const kCFStringEncodingUTF8 = 0x08000100;

const stringTypeID = CFStringGetTypeID();

// let _CFURLCreateWithFileSystemPath = Module.getExportByName(null, 'CFDictionaryGetValue')
// // console.log(_CFURLCreateWithFileSystemPath)
// Interceptor.attach(_CFURLCreateWithFileSystemPath, {
//     onEnter(args){
//         console.log('_CFURLCreateWithFileSystemPath', args[0],  args[1], args[2])
//         console.log('_CFURLCreateWithFileSystemPath', new ObjC.Object(args[1]))
//
//         this.dict = args[0];
//         this.key = args[1];
//
//         // 将 key 转换为字符串（假设是 CFString）
//         try {
//
//             const kCFStringEncodingUTF8 = 0x08000100;
//             const keyStrPtr = CFStringGetCStringPtr(this.key, kCFStringEncodingUTF8);
//             if (keyStrPtr) {
//                 this.keyStr = Memory.readUtf8String(keyStrPtr);
//                 console.log('[*] CFDictionaryGetValue called with key: ' + this.keyStr);
//             } else {
//                 console.log('[*] CFDictionaryGetValue called with non-string key');
//             }
//         } catch (e) {
//             console.log('[!] Error converting key: ' + e);
//         }
//
//     },
//     onLeave(retval){
//         console.log('CFBundleIdentifier.ret', new ObjC.Object(retval))
//
//
//         if (retval.isNull()) {
//             console.log('[*] Returned value: null');
//         } else {
//             // 尝试将返回值转换为字符串（如果适用）
//             try {
//
//
//                 const typeID = CFGetTypeID(retval);
//                 if (typeID === stringTypeID) {
//                     const valStrPtr = CFStringGetCStringPtr(retval, kCFStringEncodingUTF8);
//                     if (valStrPtr) {
//                         const valStr = Memory.readUtf8String(valStrPtr);
//                         console.log('[*] Returned value: ' + valStr);
//
//                         // 示例：修改返回值
//                         if (this.keyStr === 'CFBundleIdentifier') {
//                             const newValue = Memory.allocUtf8String('cn.12306.rails12306');
//                             console.log('[*] Replacing value with: ' + newValue);
//                             retval.replace(newValue);
//                             console.log('CFBundleIdentifier.ret', new ObjC.Object(retval))
//
//                         }
//                     }
//                 } else {
//                     console.log('[*] Returned non-string value, TypeID: ' + typeID);
//                 }
//             } catch (e) {
//                 console.log('[!] Error processing return value: ' + e);
//             }
//         }
//
//     }
// })

function h(){
    var bundle = ObjC.classes['NSBundle']
    console.log('mainBundle',bundle['+ mainBundle']()['- bundleIdentifier']())
    console.log('infoDictionary',bundle['+ mainBundle']()['- infoDictionary']())
}
// const dlopen = new NativeFunction(Module.getExportByName(null, 'dlopen'), 'pointer', ['pointer', 'int']);
// const dlsym = new NativeFunction(Module.getExportByName(null, 'dlsym'), 'pointer', ['pointer', 'pointer']);
//
// // 获取当前应用的路径
// const NSBundle = ObjC.classes.NSBundle;
// // const bundlePath = NSBundle.mainBundle().bundlePath().toString();
// // console.log('[*] Bundle Path: ' + bundlePath);
//
// // // 加载 Mach-O 解析逻辑
// // Interceptor.attach(Module.getExportByName(null, '_dyld_get_image_header'), {
// //     onEnter: function(args) {
// //         console.log('[*] _dyld_get_image_header called');
// //     }
// // });
//
// function getCodeSignInfo() {
//     const path = bundlePath + '/_CodeSignature/CodeResources';
//     const openPtr = Module.getExportByName(null, 'open');
//     const readPtr = Module.getExportByName(null, 'read');
//
//     const fd = new NativeFunction(openPtr, 'int', ['pointer', 'int'])(Memory.allocUtf8String(path), 0); // O_RDONLY
//     if (fd != -1) {
//         const buffer = Memory.alloc(1024);
//         const bytesRead = new NativeFunction(readPtr, 'int', ['int', 'pointer', 'int'])(fd, buffer, 1024);
//         if (bytesRead > 0) {
//             const data = Memory.readUtf8String(buffer, bytesRead);
//             console.log('[*] CodeSignature Data: ' + data.substring(0, 100) + '...');
//         }
//         const closePtr = Module.getExportByName(null, 'close');
//         new NativeFunction(closePtr, 'int', ['int'])(fd);
//     } else {
//         console.log('[*] Failed to open CodeResources');
//     }
// }
//
// setImmediate(getCodeSignInfo)
function a(){
    let uidevice = ObjC.classes['UIDevice']['currentDevice']();
    console.log('uidevice', uidevice)
    console.log(uidevice['identifierForVendor']()
    )
}


if (ObjC.available) {
    // 枚举所有加载的模块（包括 dylib）
    Process.enumerateModules({
        onMatch: function (module) {
            if (module.path.endsWith('.dylib')) {
                console.log('Loaded dylib: ' + module.name + ' at ' + module.path,JSON.stringify(module));
            }
        },
        onComplete: function () {
            console.log('Enumeration complete.');
        }
    });

    var LSApplicationWorkspace = ObjC.classes.LSApplicationWorkspace;
    var workspace = LSApplicationWorkspace.defaultWorkspace();

    // 调用 installedApplications 方法获取应用列表
    var apps = workspace.allInstalledApplications();

    // 遍历应用列表
    for (var i = 0; i < apps.count(); i++) {
        var app = apps.objectAtIndex_(i);
        console.log("Bundle ID: " + app.bundleIdentifier());
        console.log("App Name: " + app.localizedShortName());
        console.log("Path: " + app.bundleContainerURL().path());
        console.log("---");
    }
}
